package collection.list;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;

/**
 * --add-opens java.base/java.lang=ALL-UNNAMED
 * --add-opens java.base/java.util=ALL-UNNAMED
 * --add-opens java.base/java.nio=ALL-UNNAMED
 * --add-opens java.base/sun.nio.ch=ALL-UNNAMED
 * 需要添加JVM options指令
 */
public class Test5 {
    public static void main(String[] args) throws Exception{
        ArrayList<Integer> list = new ArrayList<>();
        showSize(list);
        Collections.addAll(list,1,2);
        showSize(list);
    }

    public static void showSize(ArrayList<Integer> list) throws Exception {
        Class<?> clazz = list.getClass();
        Field elementData = clazz.getDeclaredField("elementData");
        elementData.setAccessible(true);
        Object[] o = (Object[])elementData.get(list);
        System.out.println(o.length);
    }
}
